﻿var cityNum = "";
var tr1;
function WriteCityMessage() {

    //$("#tb_moreCity").attr("visibility", "hidden");
    document.getElementById("tb_moreCity").style["visibility"] = 'hidden';
    
    initHotCity();
   

}


//得到所有的城市信息
function initHotCity() {
    //通过JSON来得到所有的城市的数据
    //grade = 1 是推荐城市，显示在首页； grade=2 是热点城市，显示在“更多。。”的城市列表页面
    $.getJSON('/Home/HotCity/2', { t: new Date() }, function(j) {
    document.getElementById("div_wait").style["visibility"] = 'visible';
       // $("#div_wait").attr("visibility", "visible");

        cityNum = j.length;
        //调用getMoreCityPageNum调用这个分页方法来对现在所有的数据进行分页显示
        getMoreCityPageNum(cityNum);
        var arr = new Array();
        var s = null;
        for (var i = 0; i < j.length; i++) {
            //得到城市相应的信息
            var value = j[i];
            
            arr = value.split('|');
            //得到城市名
            var HotCityName = arr[0];
            //得到城市的ID
            var HotCityID = arr[1];
            var HotCityGrade = arr[2];
            var HotCityLevel = arr[3];
            //城市信息
            var HotCityLink = arr[4];
            //对城市信息进行字数控制
            if (HotCityLink.length > 85) {
                HotCityLink = HotCityLink.substring(0, 85);
            }
            //得到城市的信息
            var HotCityDescription = arr[5];
            //得到城市的连接地址
            var HotCityHref = arr[6] + arr[7];
            var shopImg = HotCityHref.split('/');

            //得到城市的城市图片
            if (shopImg[(shopImg.length) - 1] == '' || shopImg[(shopImg.length) - 1] == 'null') {
                HotCityHref = '/Content/img/home/iniImg.bmp';
            }
            //alert(HotCityHref);
            var linkCity = '/City/cityDetail/' + HotCityID;
            //把相应的数据加载到相应的标签中
            $("#cityName" + (i + 1)).html(HotCityName);
            $("#message" + (i + 1)).html(HotCityLink);
            $("#City" + (i + 1)).attr("title", HotCityName + "欢迎您");
            $("#City" + (i + 1)).attr("href", '/City/cityDetail/' + HotCityID);
            $("#firstCity" + (i + 1)).attr("href", '/City/cityDetail/' + HotCityID);
            $("#particularMessage" + (i + 1)).html("...>>>>>>详细信息");
            $("#img" + (i + 1)).attr("src", '/Content/img/CityImg/' + HotCityHref);




            $("#links" + (i + 1)).show();

            //            document.getElementById("moreCityPageNum").style["visibility"] = "visible";
            //            document.getElementById("cityName" + (i + 1)).style["visibility"] = "visible";
            //            document.getElementById("message" + (i + 1)).style["visibility"] = "visible";
            //            document.getElementById("City" + (i + 1)).style["visibility"] = "visible";
            //            document.getElementById("firstCity" + (i + 1)).style["visibility"] = "visible";
            //            document.getElementById("particularMessage" + (i + 1)).style["visibility"] = "visible";
            //            document.getElementById("img" + (i + 1)).style["visibility"] = "visible";
            // document.getElementById("links" + (i + 1)).style["visibility"] = "visible";

            $(function() {
                $('#links tr').biggerlink();

                $('#links' + (i) + ' tr').biggerlink();


            });

        }


        document.getElementById("div_wait").style["visibility"] = 'hidden';
        document.getElementById("tb_moreCity").style["visibility"] = 'visible';
    });        // end getJSON

}

//得到更多城市里一共分多少页
function getMoreCityPageNum(cityNum) {



    tr_id = $("#moreCityPageNum>tbody>tr>td:last").attr("id");
    tr_id++;
    var str1 = "<tr id = '" + tr_id + "'>";
    var str2 = "</tr>";
    var std = "";
    //alert(tr_id);
            //得到一共需要分成几页
            var s = cityNum / 20;
            var page = 0;
           page = parseInt(s);

            if (s > page) {
                page = page + 1;
            }
    //通过循环来把页码显示在页面上
            for (var j = 0; j < page; j++) {


                std += "<td width='20px'><a href='#' onclick='pageNum(" + (j + 1) + ");' id='pageUrl'" + (j + 1) + " class='link'>" + (j + 1) + "</a></td>";   

}

var strtd = str1 + std + str2;

$('#moreCityPageNum').append(strtd);















    //得到一共要分多少页
    
//    tr1 = document.getElementById('moreCityPageNum').insertRow();
//        //得到一共需要分成几页
//        var s = cityNum / 20;
//        var page = 0;

//        page = parseInt(s);

//        if (s > page) {
//            page = page + 1;
//        }
////通过循环来把页码显示在页面上
//        for (var j = 0; j < page; j++) {

////            var td1 = tr1.insertCell();
//            //            td1.width = "20px";
//            $.each(tr1, function(j) {
//            $($(tr1[j]).children()[1]).html("");
//            });

////            td1.innerHTML = "<a href='#' onclick='pageNum(" + (j + 1) + ");' id='pageUrl'" + (j + 1) + " class='link'>" + (j + 1) + "</a>";
//        }     
}


//更多城市的分页程序
function pageNum(page) {
    
    var arr = new Array();
    var s = null;
    var cityNum = "";
    //通过JSON来得到相应城市信息
    $.getJSON('/Home/getMoreCityPage/' + page, { t: new Date() }, function(j) {

        if (j.length < 20) {
            cityNum = j.length;
        } else {
            cityNum = 20;
        }

        for (var i = 0; i < cityNum; i++) {
            //得到相应的城市信息
            var values = j[i];
            arr = values.split('|');
            //得到城市ID
            var cityID = arr[0];
            //得到城市名
            var cityName = arr[1];
            //得到城市信息
            var cityDescription = arr[2];
            //得到城市图片
            var cityImg = arr[3];
            //判断所查询出的城市是否不是以下几个城市,如果不是的话才对其进行显示
            if (cityID != '3' || cityID != '4' || cityID != '5' || cityID != '9' || cityID != '10' || cityID != '20' || cityID != '41' || cityID != '43' || cityID != '44' || cityID != '46' || cityID != '48' || cityID != '50' || cityID != '57' || cityID != '59' || cityID != '60' || cityID != '61' || cityID != '62' || cityID != '63') {
                if (cityDescription.length > 85) {
                    cityDescription = cityDescription.substring(0, 85);
                }

                var linkCity = '/City/cityDetail/' + cityID;
                //将得到的数据添加到响应的标签中去
                $("#cityName" + (i + 1)).html(cityName);
                $("#message" + (i + 1)).html(cityDescription);
                $("#City" + (i + 1)).attr("title", cityName + "欢迎您");
                $("#City" + (i + 1)).attr("href", '/City/cityDetail/' + cityID);
                $("#firstCity" + (i + 1)).attr("href", '/City/cityDetail/' + cityID);
                $("#particularMessage" + (i + 1)).html("...>>>>>>详细信息");
                $("#img" + (i + 1)).attr("src", '/Content/img/CityImg/' + cityImg);


                $("#links" + (i + 1)).show();
                $(function() {
                    $('#links tr').biggerlink();

                    $('#links' + (i) + ' tr').biggerlink();


                });
            }

            if (cityNum < 20) {

                for (var t = cityNum; t < 20; t++) {

                    $("#links" + (t + 1)).hide();

                }
            }

        }
    })
}

